#!/sbin/openrc-run

description="Start/stop the tipidee services"

depend()
{
	need s6
	after net
	after localmount
}

_get_services()
{
	list=
	if "$HTTP" ; then
		if test -n "$TIPIDEED_IPv4" ; then
			list="$list httpd-4"
		fi
		if test -n "$TIPIDEED_IPv6" ; then
			list="$list httpd-6"
		fi
	fi
	if "$HTTPS" ; then
		if test -n "$TIPIDEED_IPV4" ; then
			list="$list httpsd-4"
		fi
		if test -n "$TIPIDEED_IPV6" ; then
			list="$list httpsd-6"
		fi
	fi
	echo $list
}

stop()
{
	ebegin "Stopping the tipidee services"
	for i in `_get_services` ; do
		s6-svunlink /run/service "$i"
	done
	eend $?
}

start()
{
	ebegin "Starting the tipidee services"
	for i in `_get_services` ; do
		s6-svlink -t10000 /run/service "/var/lib/tipidee/services/$i"
	done
	eend $?
}

status()
{
	for i in `_get_services` ; do
		echo -n "${i}: "
		s6-svstat "/run/service/${i}"
	done
}

restart()
{
	for i in `_get_services` ; do
		s6-svc -rwR "/run/service/$i"
	done
}
